﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Shumei.EFCore.Model;

namespace Shumei.EFCore.SimpleService
{
    public class ProductService:BaseSimpleDAL<Product>
    {
        public ProductService(): base()
        {

        }

        public List<Product> GetProductsList(int page, out int totalPage, int num = 10)
        {
            List<Product> res;
            try
            {
                res = Entities.OrderBy(x => x.Id).Skip((page - 1) * 10).Take(num).ToList();
                totalPage = (Entities.Count() / num) + 1;
            }
            catch
            {
                res = new List<Product>();
                totalPage = 1;
            }
            return res;
        }

        public Product GetProductDetail(int id)
        {
            try
            {
                return Entities.Find(id);
            }
            catch
            {
                return null;
            }
        }
    }
}
